
	** Urban status
	
		use "$dir/rawdata/LSMS Tanzania/2010/HH_SEC_A.dta", clear
		
		gen w2_urban=y2_rural==0 if !missing(y2_rural)
		
		keep y2_hhid w2_*
		
		tempfile urban
		save `urban', replace
		
	** Roster
	
		use "$dir/rawdata/LSMS Tanzania/2010/HH_SEC_B.dta", clear
	
		gen w2_female=hh_b02==2 if !missing(hh_b02)
		gen w2_age=hh_b04
		
		gen w2_inhh=1 if hh_b09_2!="X"
		
		gen w2_married=(hh_b19==1 | hh_b19==2) if !missing(hh_b19)
		
		bys y2_hhid: egen w2_hh_size=total(w2_inhh)
		
		keep y2_hhid indidy2 hhid_2008 w2_*
		
		tempfile roster
		save `roster', replace
		
	** Employment 
	
		use "$dir/rawdata/LSMS Tanzania/2010/HH_SEC_E1.dta", clear
	
		** Working for a wage outside the household
			gen w2_work_outsideHH=(hh_e12==1 | hh_e29==1) if (!missing(hh_e12) | !missing(hh_e29))
			gen w2_work_outsideHH_hrs=hh_e25
			replace w2_work_outsideHH_hrs=w2_work_outsideHH_hrs+hh_e40 if !missing(hh_e40)
			replace w2_work_outsideHH_hrs=0 if w2_work_outsideHH==0
			
		** Working in agriculture for a HH member
			gen w2_work_agHH_hrs=hh_e78
			gen w2_work_agHH=hh_e77==1 if !missing(hh_e77)
			
		** Working in HH business
			gen w2_work_bizHH_hrs=hh_e75
			gen w2_work_bizHH=(hh_e51==1 | hh_e74==1) if (!missing(hh_e51) | !missing(hh_e74))
			
		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w2_worked_last7days=rowmax(w2_work_outsideHH w2_work_agHH w2_work_bizHH)
		
		** Hours worked in last 7 days
			egen w2_work_hrs=rowtotal(w2_work_outsideHH_hrs w2_work_agHH_hrs w2_work_bizHH_hrs)
			replace w2_work_hrs=. if missing(w2_work_outsideHH_hrs) & missing(w2_work_agHH_hrs) & missing(w2_work_bizHH_hrs)
		
		keep y2_hhid indidy2 w2_*
		
		tempfile employment
		save `employment', replace
		
	** Illness and injury
		
		*n/a

	** Disabilities

		use "$dir/rawdata/LSMS Tanzania/2010/HH_SEC_D.dta", clear

		** Difficulty seeing
		tab1 hh_d17
		gen w2_diff_seei=1 if inlist(hh_d17, 3, 4, 5) 
		replace w2_diff_seei=0 if inlist(hh_d17, 1, 2)
		replace w2_diff_seei=. if inlist(hh_d17, .)
		tab1 w2_diff_seei

		** Difficulty hearing
		tab1 hh_d19
		gen w2_diff_hear=1 if inlist(hh_d19, 3, 4, 5) 
		replace w2_diff_hear=0 if inlist(hh_d19, 1, 2)
		replace w2_diff_hear=. if inlist(hh_d19, .)
		tab1 w2_diff_hear

		** Difficulty walking or climbing stairs	
		tab1 hh_d21
		gen w2_diff_walk_clim=1 if inlist(hh_d21, 3, 4, 5) 
		replace w2_diff_walk_clim=0 if inlist(hh_d21, 1, 2)
		replace w2_diff_walk_clim=. if inlist(hh_d21, .)
		tab1 w2_diff_walk_clim

		** Difficulty remembering or concentrating
		tab1 hh_d23
		gen w2_diff_reme=1 if inlist(hh_d23, 3, 4, 5) 
		replace w2_diff_reme=0 if inlist(hh_d23, 1, 2)
		replace w2_diff_reme=. if inlist(hh_d23, .)
		tab1 w2_diff_reme

		** Difficulty with self-care
		tab1 hh_d25
		gen w2_diff_self_care=1 if inlist(hh_d25, 3, 4, 5) 
		replace w2_diff_self_care=0 if inlist(hh_d25, 1, 2)
		replace w2_diff_self_care=. if inlist(hh_d25, .)
		tab1 w2_diff_self_care

		** Difficulty communicating
		tab1 hh_d27
		gen w2_diff_comm=1 if inlist(hh_d27, 3, 4, 5) 
		replace w2_diff_comm=0 if inlist(hh_d27, 1, 2)
		replace w2_diff_comm=. if inlist(hh_d27, .)
		tab1 w2_diff_comm

		keep y2_hhid indidy2 w2_*	
	    tempfile disabilities
		save `disabilities', replace

	
	** Merge and save
	
		use `roster', clear
		merge 1:1 y2_hhid indidy2 using `employment', gen(merge_employment)
		merge 1:1 y2_hhid indidy2 using `disabilities', gen(merge_disabilities)
		merge m:1 y2_hhid using `urban', gen(merge_urban)

		
		ren y2_hhid hhid_w2
		ren indidy2 indiv_w2
		ren hhid_2008 hhid_w1
		
		save "$dir/data/tza_w2_individual.dta", replace
